package com.zyh.pool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @Author zyh
 * @Date 2024/8/12 11:11
 * @Description newSingleThreadExecutor 线程池
 *      核心线程数量1，最大线程数量1，核心线程存活时间0L，LinkedBlockingQueue 无界阻塞队列
 */

public class ThreadPoolDemo3 {
    public static void main(String[] args) {
        ExecutorService threadPool = Executors.newSingleThreadExecutor();
        threadPool.submit(new Runnable() {
            @Override
            public void run() {
                System.out.println(3);
            }
        });
        threadPool.submit(new Runnable() {
            @Override
            public void run() {
                System.out.println(5);
            }
        });
        threadPool.submit(new Runnable() {
            @Override
            public void run() {
                System.out.println(4);
            }
        });
        threadPool.submit(new Runnable() {
            @Override
            public void run() {
                System.out.println(2);
            }
        });
        threadPool.submit(new Runnable() {
            @Override
            public void run() {
                System.out.println(1);
            }
        });
        threadPool.shutdown();
    }
}
